/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Control;

import DAO.EspacoDAO;
import Model.Espaco;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;

/**
 *
 * @author 0433101
 */
public class removerEspaco extends Processor {

    @Override
    public void execute() throws ServletException, IOException {
        getResponse().setContentType("text/html;charset=UTF-8");
        String id = getRequest().getParameter("id");
        try{
            int id_espaco = Integer.parseInt(id);
            boolean removido = EspacoDAO.remove(id_espaco);
            if(removido){
                String mensagem = "Espaço " + id_espaco + " removido!";
                getRequest().setAttribute("mensagem", mensagem);
                RequestDispatcher rd = getRequest().getRequestDispatcher("menuAdministrador.jsp");
                rd.forward(getRequest(), getResponse());
            }else{
                String mensagem = "Erro na operação!";
                getRequest().setAttribute("mensagem", mensagem);
                RequestDispatcher rd = getRequest().getRequestDispatcher("menuAdministrador.jsp");
                rd.include(getRequest(), getResponse());
            }
        }
        catch(SQLException e){
            throw new ServletException(e);
        }
        catch(ClassNotFoundException e){
            throw new ServletException(e);
        }
        catch(Exception e){
            throw new ServletException(e);
        }
    }
    
}
